<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>VUE3: v-bind绑定class</title>
    <style>
      .active {
        color: yellow;
        background: red;
      }

      .header-2 {
        padding: 0.25rem;
        border: 1px solid #666;
      }
    </style>
  </head>
  <body>
    <div id="app"></div>

    <template id="tpl">
      <!-- 绑定对象形式的class -->
      <h2 class="header-2" :class="{active:isActive}">Hello, 世界🌏</h2>
      <!-- 绑定数组形式的class -->
      <h2 class="header-2" :class="[!isActive ? 'active': '', 'foo', 'bar']">
        Hello, 世界🌏
      </h2>
      <!-- 绑定数组形式的class，可以嵌套对象形式 -->
      <h2 class="header-2" :class="[{active:!isActive}, 'foo', 'bar']">
        Hello, 世界🌏
      </h2>
      <div>
        <button @click="isActive = !isActive">改变</button>
      </div>
    </template>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
      Vue.createApp({
        template: "#tpl",
        data() {
          return {
            isActive: true,
          };
        },
      }).mount("#app");
    </script>
  </body>
</html>
